#ifndef _RTTYPES_H_
#define _RTTYPES_H_

#include <QVector>
#include <QMetaType>

typedef QVector<int> RtIntVector;
typedef QVector<unsigned int> RtUintVector;
typedef QVector<double> RtDoubleVector;

Q_DECLARE_METATYPE(RtIntVector)
Q_DECLARE_METATYPE(RtUintVector)
Q_DECLARE_METATYPE(RtDoubleVector)

class QScriptEngine;

int registerVectorTypes(QScriptEngine* eng);

#include <sys/types.h>
#include <sys/timeb.h>
#include <time.h>

#include <QString>
#include <QDateTime>

/** Time representation in RtLab.

  \ingroup RtCore

  Time is represented internaly as a double number
  corresponding to seconds since 1 Jan 1970
  as returned by the POSIX ftime function.
  It is recorded with millisecond resolution.
  */
class RtTimeValue
{
	double v_;

public:

	/// default constructor
	RtTimeValue() : v_(0.0)	{}
	/// construct from double
	explicit RtTimeValue(double d) : v_(d)	{}
	/// copy constructor
	RtTimeValue(const RtTimeValue& rhs) : v_(rhs.v_)	{}
	/// copy
	RtTimeValue& operator=(const RtTimeValue& rhs)
	{
		v_ = rhs.v_;
		return *this;
	}

	/// type conversion operator to double
	operator double() { return v_; }

	/// return current time in RtTimeValue format
	static RtTimeValue now()
	{
		_timeb t;
		_ftime(&t);
		return RtTimeValue(t.time + 0.001*t.millitm);
	}

	/// split in sec and millisec
	void split(int& sec, int& msec)
	{
		sec = (int)v_;
		msec = (int)(1000*(v_-sec));
	}

	/// convert to string
	QString toString()
	{
		int s,ms;
		split(s,ms);
		return QString("%1.%2")
			.arg(QString(QByteArray(_ctime32((__time32_t*)&s)+11,8)))
			.arg(ms,3,10,QChar('0'));
	}

	/// convert to QDateTime
	QDateTime toDateTime()
	{
		return QDateTime::fromMSecsSinceEpoch((qint64)(1000*v_));
	}

};

#endif

